package com.gxh.service.impl;

import com.github.pagehelper.PageHelper;
import com.gxh.context.BaseContext;
import com.gxh.dto.FeedbackDTO;
import com.gxh.dto.FeedbackPageQueryDTO;
import com.gxh.entity.Feedback;
import com.gxh.mapper.FeedbackMapper;
import com.gxh.result.PageResult;
import com.gxh.service.FeedbackService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class FeedbackServiceImpl implements FeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;

    /**
     * 用户反馈
     * @param feedbackDTO
     */
    public void feedback(FeedbackDTO feedbackDTO) {
        Feedback feedback = new Feedback();
        BeanUtils.copyProperties(feedbackDTO, feedback);
        feedback.setCreateUser(BaseContext.getCurrentId());
        feedback.setCreateTime(LocalDateTime.now());
        feedbackMapper.insert(feedback);
    }

    /**
     * 分页查询
     * @param feedbackPageQueryDTO
     * @return
     */
    public PageResult pageQuery(FeedbackPageQueryDTO feedbackPageQueryDTO) {
        PageHelper.startPage(feedbackPageQueryDTO.getPage(), feedbackPageQueryDTO.getPageSize());
        PageResult pageResult = feedbackMapper.pageQuery(feedbackPageQueryDTO);
        long total = pageResult.getTotal();
        List records = pageResult.getRecords();
        return new PageResult(total, records);
    }
}
